package Singleton;
/**
 *
 * @description: 懒汉式单例模式-练习
 * @author: jun
 * @time:  2020-05-28
 */
public class LazySingleton {
    public static void main(String[] args){
        LazySingleton instance1 = LazySingleton.getInstance();
        LazySingleton instance2 = LazySingleton.getInstance();
        System.out.print(instance1==instance2);
    }

    private LazySingleton(){

    }

    private static LazySingleton lazyInstance = null;

    public static synchronized LazySingleton getInstance(){
        if(lazyInstance == null){
            lazyInstance = new LazySingleton();
        }
        return lazyInstance;
    }
}
